import request from '@/utils/request'
import { tansParams } from '@/utils/index'

export function getMenusTree(params) {
  return request({
    url: '/api/sys/menu/getTree',
    method: 'get',
    params
  })
}

export function getMenus(params) {
  return request({
    url: '/api/sys/menu/page',
    method: 'get',
    params
  })
}


export function findAll(ids) {
  const data = ids.length || ids.length === 0 ? ids : Array.of(ids)
  return request({
    url: '/api/sys/menu/findAll',
    method: 'post',
    data
  })
}

export function getChildIds(id) {
  return request({
    url: '/api/sys/menu/childIds/' + id,
    method: 'get'
  })
}

export function buildMenus() {
  return request({
    url: '/api/sys/menu/build',
    method: 'get'
  })
}

export function add(data) {
  return request({
    url: '/api/sys/menu/insert',
    method: 'post',
    data
  })
}

export function del(ids) {
  return request({
    url: '/api/sys/menu/delete',
    method: 'post',
    data: ids
  })
}

export function edit(data) {
  return request({
    url: '/api/sys/menu/update',
    method: 'post',
    data
  })
}

export function importPrivilege(ids) {
  return request({
    headers: {
      'Content-Type': 'application/x-www-form-urlencoded',
    },
    url: '/api/sys/menu/importPrivilege',
    method: 'post',
    data: {menuIds: ids},
    transformRequest: [(data) = > {
      return tansParams(data)
    }
]
})
}


export default { add, edit, del, getMenusTree, findAll, getMenus, getChildIds, importPrivilege }
